home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / clipper / nannws22.arc / BMOUSE.ASM next >
Assembly Source File  |  1987-12-08  |  16KB  |  440 lines

  1. ;*******************************************
  2. ;* Filename..............:BMOUSE.asm
  3. ;*------------------------------------------
  4. ;* PART I - Adapted from.: PC Magazine, Vol.6 No.13; July 21,1987
  5. ;*                         Article: MOUSE SOFTWARE by Jeff Prosise
  6. ;* Modified by...........: Bao Hoang
  7. ;* Date..................: August 1987
  8. ;*
  9. ;* Syntax.......: memvar = M_SET_ON()
  10. ;*              : memvar = M_SET_OFF()
  11. ;*
  12. ;* Return values: M_SET_ON()  - .T. if everything is O.K. and .F.
  13. ;*                              if something is wrong (i.e., 
  14. ;*                              mouse driver not installed)
  15. ;*                M_SET_OFF() - always returns .T. and return
  16. ;*                              value can pretty much be ignored
  17. ;*
  18. ;*                CSR_ON()    - .T. if everything is O.K. and .F.
  19. ;*                              if it was not able to install the
  20. ;*                              routine (i.e., mouse driver not
  21. ;*                              installed)
  22. ;*
  23. ;*                CSR_OFF()    - always returns a .T.
  24. ;*
  25. ;*******************************************
  26.  
  27.  
  28. ;*** declare callable routines as PUBLIC
  29. ;
  30.      public M_SET_ON
  31.      public M_SET_OFF
  32.      public CSR_ON
  33.      public CSR_OFF
  34.      public LD_SCR
  35.  
  36. ;*** declare Clipper's procedures for returning variables as FAR
  37. ;
  38.      extrn          __RETL:far    ; returns logical type
  39.      extrn          __PARNI:far
  40.  
  41. ;*** define keys to insert based on mouse conditions.
  42. ;
  43.      LB             equ 1C0Dh     ; set LEFT button to RETURN key
  44.      CB             equ 3B00h     ; set CENTER button to F1 key
  45.      RB             equ 011Bh     ; set RIGHT button to ESC key
  46.  
  47.  
  48. ;*** Define keyboard buffer area.
  49. ;
  50. BIOS_DATA segment at 40h
  51.      org                 1ah
  52.      BUFFER_HEAD         dw   ?   ;pointer to the keybord
  53.                                   ;buffer head
  54.      BUFFER_TAIL         dw   ?   ;pointer to the keyboard
  55.                                   ;buffer tail
  56.      org                 80h
  57.      BUFFER_START        dw   ? ;starting keyboard buffer address
  58.      BUFFER_END          dw   ? ;ending keyboard buffer address
  59. BIOS_DATA ends
  60. ;
  61. ;
  62. ;
  63. CODE segment 'CODE'         ; declare code segment of class CODE
  64.     assume cs:CODE,ds:BIOS_DATA
  65.  
  66.     VCOUNT         db   10        ; vertical delay counter
  67.     HCOUNT         db   10        ; horizontal delay counter
  68.     HFLAG          dw   ?         ; horizontal count sign flag
  69.     VFLAG          dw   ?         ; vertical count sign flag
  70.     KEYCODE        db   4Dh,4Bh,50h,48h ;keycodes for cursor keys
  71.  
  72.  
  73.     EIGHTY         db   80   ; to allow multiply by 80
  74.     SV_AX          dw   ?    ; temporary storage of AX register
  75.     SV_DX          dw   ?    ; temporary storage of DX register
  76.  
  77.     SCR_MAP        db   2000 dup  (0) ;screen map 80x25
  78.     SCR_OFF        dw   0         ; screen offset
  79.     P_LEN          dw   0         ; prompt length
  80.     FILL_CHAR      db   0         ; character to fill are with
  81.  
  82.  
  83.  
  84. ;=========================================
  85. ;= PART I:
  86. ;=
  87. ;= MOUSE, M_SET_ON(), M_SET_OFF()
  88. ;=
  89. ;= Used for the "keyboard emulation" mouse.  These are the mouse
  90. ;= routines used to make the highlighting bar (w/ @...prompt/menu
  91. ;= to) move when you move the mouse.
  92. ;=========================================
  93. ;
  94. MOUSE proc far
  95. ;
  96. ; determine which event occured, and branch accordingly
  97. ;
  98.     test ax,2           ; left button pressed?
  99.     jnz  LEFT           ; if yes, then go insert 'LB' into buffer
  100.     test ax,8           ; right button pressed?
  101.     jnz  RIGHT          ; if yes, then go insert 'RB' into buffer
  102.     test ax,32          ; center button pressed? (PC MOUSE)
  103.     jnz  CENTER         ; if yes, then go insert 'CB' into buffer
  104.  
  105. MOUSE0:
  106.     mov  ax,11               ; use mouse driver's function 11
  107.     int  51                  ; read mouse motion counters
  108.     mov  HFLAG,0             ; initialize sign flags
  109.     mov  VFLAG,2             ;
  110.     xor  al,al               ; zero AL for extended keycode
  111.     cmp  cx,0                ; horizontal count positive?
  112.     jge  MOUSE1              ; yes, then branch
  113.     inc  HFLAG               ; record negative condition
  114.     neg  cx                  ; convert negative to positive
  115.  
  116. MOUSE1:
  117.     cmp  dx,0                ; vertical count positive
  118.     jge  MOUSE2              ; yes, then branch
  119.     inc  VFLAG               ; record negative condition
  120.     neg  dx                  ; convert negative to positive
  121.  
  122. MOUSE2:
  123.     mov  bx,HFLAG            ; assume motion was horizontal
  124.     cmp  cx,dx               ; was assumption correct?
  125.     jae  HORIZ               ; yes, then branch
  126.     mov  bx,VFLAG            ; no, then correct it
  127.     dec  VCOUNT              ; decrement vertical delay count
  128.     jz   MOUSE3              ; continue if count is zero
  129.     jmp  GET_OUT
  130.  
  131. HORIZ:
  132.     dec  HCOUNT
  133.     jz   MOUSE3
  134.  
  135. GET_OUT:
  136.     ret
  137.  
  138. MOUSE3:
  139.     mov  HCOUNT,10
  140.     mov  VCOUNT,10           ; reset delay counter
  141.     mov  ah,KEYCODE[bx]      ; get keycode from table
  142.     call INSERT              ; insert it into keyboard buffer
  143.     jmp  RETURN
  144.  
  145. LEFT:
  146.     mov  ax,LB               ; load pre-defined 'LB' keycode 
  147.                              ; into buffer
  148.     call INSERT              ; insert it into buffer
  149.     jmp  RETURN
  150. RIGHT:
  151.     mov  ax,RB               ; load pre-defined 'RB' keycode
  152.                              ; into buffer
  153.     call INSERT              ; insert it into buffer
  154.     jmp  RETURN
  155.  
  156. CENTER:
  157.     mov  ax,CB               ; load pre-defined 'CB' keycode
  158.                              ; into buffer
  159.     call INSERT              ; insert it into buffer
  160.  
  161. RETURN:
  162.     ret
  163.  
  164. MOUSE endp
  165. ;
  166. ;
  167. ;
  168. ;****************************************
  169. ;** M_SET_ON() : routine to set up a function to be called upon
  170. ;**              mouse activity, using the mouse driver's 
  171. ;**              function 12.
  172. ;****************************************
  173. M_SET_ON proc far
  174.     push bp                  ; save everything as documented in
  175.     mov  bp,sp               ; Aut '86 Nantucket News or you
  176.     push ds                  ; will blow up!
  177.     push es                  ;
  178.     mov  ax,0                ; use function 0 of driver to see
  179.     int  33h                 ; if mouse and driver are installed
  180.     or   ax,ax               ; is there a mouse?
  181.     jne  OK                  ; yes, continue
  182.     mov  bx,0                ; return to Clipper a .F. to tell
  183.     push bx                  ; it that M_SET_ON() failed to set
  184.     call __retl              ; up the routine (extended interface)
  185.     jmp  DONE                ; go back to Clipper
  186.  
  187. OK:
  188.     mov  ax,15               ; use function 15 of mouse driver to
  189.     mov  cx,400              ; set the mouses sensitivity
  190.     mov  dx,800              ;
  191.     int  33h                 ;
  192.     mov  ax,seg MOUSE        ; tell function 12 where to find the
  193.     mov  es,ax               ; the mouse routine
  194.     mov  dx,offset MOUSE     ;
  195.     mov  ax,12               ; use function 12
  196.     mov  cx,0000000000101011b     ; set up the mask for buttons 
  197.                                   ; and cursor
  198.     int  33h               ; set it up!
  199.     mov  bx,1              ; return a .T. to Clipper to tell it
  200.     push bx                ; that the installation was successful
  201.     call __retl            ; (using Clipper's extended interface)
  202.  
  203. DONE:
  204.     pop  bx                  ; restore the stack or DIE!!!!
  205.     pop  es                  ;
  206.     pop  ds                  ;
  207.     pop  bp                  ;
  208.     ret                      ; exit and pray!!
  209. M_SET_ON endp
  210. ;
  211. ;
  212. ;
  213. ;***********************************************
  214. ;** M_SET_OFF() : routine to disable the mouse routine so that
  215. ;**               accidentally hitting the mouse won't cause the
  216. ;**               cursor keys to be inserted into the keyboard
  217. ;**               buffer
  218. ;***********************************************
  219. M_SET_OFF proc far
  220.     push bp             ; save these registers as usual
  221.     mov  bp,sp          ;
  222.     push ds             ; or DIE!!!!!
  223.     push es             ;
  224.     mov  ax,0           ; use function 0 of the mouse driver
  225.     int  33h            ; to reset the mouse settings which
  226.     mov  bx,1           ; effectively turns off the mouse routine
  227.     push bx             ; return a .T. which really has no
  228.     call __retl         ; meaning but needs to be done to allow
  229.     pop  bx             ; the routine to be used as a UDF without
  230.     pop  es             ; hanging. Restore the stack or hang
  231.     pop  ds             ; like a
  232.     pop  bp             ; bleep, bleep !!!!
  233.     ret                 ;
  234. M_SET_OFF endp
  235.  
  236.  
  237. ;=====================================================
  238. ;= PART II:
  239. ;=
  240. ;= CSR_ON(),CSR_OFF(),MOUSER
  241. ;=
  242. ;= Routines used to simulate a "free floating" mouse cursor 
  243. ;= (Mac-like).
  244. ;=====================================================
  245. ;
  246. ;
  247. ;*****************************************************
  248. ;* CSR_ON() - Sets the mouse cursor on.
  249. ;*****************************************************
  250. CSR_ON proc    far
  251.      push      bp             ; save everything as documented in
  252.      mov       bp,sp          ; Aut '86 Nantucket News or you
  253.      push      ds             ; will blow up!
  254.      push      es             ;
  255.      mov       ax,0           ; use function 0 of driver to see
  256.      int       33h            ; if mouse and driver are installed
  257.      or        ax,ax          ; is there a mouse?
  258.      jne       OK2            ; yes, continue
  259.      mov       bx,0           ; return to Clipper a .F. to tell
  260.      push      bx             ; it that CSR_ON() failed to turn
  261.      call      __retl         ; on the mouse cursor
  262.      jmp       DONE2          ; go back to Clipper
  263.  
  264. OK2: mov       ax,1           ; use function 1 of mouse driver
  265.      int       33h            ; to turn cursor on
  266.      mov       ax,seg MOUSER       ; tell function 12 where to
  267.      mov       es,ax               ; find the mouse routine
  268.      mov       dx,offset MOUSER    ;
  269.      mov       ax,12               ; use function 12
  270.      mov       cx,0000000000101010b; set up the mask for buttons
  271.                                    ; and cursor
  272.      int       33h                 ; set it up!
  273.      mov       bx,1        ; return a .T. to Clipper to tell it
  274.      push      bx          ; that the installation was successful
  275.      call      __retl      ; (using Clipper's extended interface)
  276.  
  277. DONE2:
  278.      pop       bx             ; restore the stack or DIE!!!!
  279.      pop       es             ;
  280.      pop       ds             ;
  281.      pop       bp             ;
  282.      ret                      ; exit and pray!!
  283.  
  284. CSR_ON    endp
  285. ;
  286. ;
  287. ;*****************************************************
  288. ;* CSR_OFF() - Sets the mouse cursor off.
  289. ;*****************************************************
  290. CSR_OFF   proc far
  291.      push      bp             ; save everything as documented in
  292.      mov       bp,sp          ; Aut '86 Nantucket News or you
  293.      push      ds             ; will blow up!
  294.      push      es             ;
  295.  
  296. OK3: mov  ax,2      ; use function 2 of mouse driver
  297.      int  33h       ; to turn cursor off
  298.      mov  ax,0      ; use function 0 to
  299.      int  33h       ; reset mouse...
  300.      mov  bx,1      ; return a .T. to Clipper to tell it
  301.      push bx        ; that the un-installation was successful
  302.      call __retl    ; (using Clipper's extended interface)
  303.  
  304. DONE3:
  305.      pop       bx   ; restore the stack or DIE!!!!
  306.      pop       es   ;
  307.      pop       ds   ;
  308.      pop       bp   ;
  309.      ret            ; exit and pray!!
  310.  
  311. CSR_OFF    endp
  312. ;
  313. ;
  314. ;*********************************************************
  315. ;* MOUSER - Resident mouse routine for "free form mouse"
  316. ;*********************************************************
  317. MOUSER  proc  far
  318.      mov  ax,3           ; use function 3 of 
  319.      int  33h            ; mouse interrupt to determine
  320.      mov  ax,cx          ; store horiz. position in ax
  321.      xor  ch,ch          ; 
  322.      mov  cl,3           ; 
  323.      sar  ax,cl          ; divide horiz. pos. by 8
  324.      sar  dx,cl          ; divide vert. pos by 8
  325.      mov  SV_AX,ax       ; save ax
  326.      mov  SV_DX,dx       ; save dx
  327.      mov  ax,dx          ; 
  328.      call MULT10         ; multiply vert. count by 80
  329.      mov  cl,3           ; 
  330.      shl  ax,cl          ;
  331.      add  ax,SV_AX       ; then add horiz. pos.
  332.      mov  bx,ax          ;
  333.      int  3h
  334.      cmp  SCR_MAP[bx],0  ; check to see if we are supposed to
  335.                          ; hit return
  336.      je   DO_NADA        ; don't do nothin' if it's 0
  337.      mov  al,SCR_MAP[bx] ;
  338.      xor  ah,ah
  339.      call INSERT
  340. DO_NADA:
  341.      ret
  342.  
  343. MOUSER    endp
  344. ;
  345. ;
  346. ;
  347. ;*****************************************************************
  348. ;* LD_SCR() - load the SCR_MAP with the appropriate values (called
  349. ;*            from Clipper)
  350. ;*****************************************************************
  351. LD_SCR    proc     far
  352.      push bp             ; save stack or DIE !!
  353.      mov  bp,sp
  354.      push ds
  355.      push es
  356.  
  357.      mov  ax,1           ; get first parameter (SCR_OFF)
  358.      push ax             ;
  359.      call __parni        ;
  360.      mov  SCR_OFF,ax     ;
  361.      pop  ax
  362.  
  363.      mov  ax,2           ; get second parameter (P_LEN)
  364.      push ax             ;
  365.      call __parni        ;
  366.      mov  P_LEN,ax       ;
  367.      pop  ax
  368.  
  369.      mov  ax,3           ; get third parameter (ASC(<expC>))
  370.      push ax             ;
  371.      call __parni        ;
  372.      mov  SV_AX,ax       ;
  373.      pop  ax
  374.      mov  ax,SV_AX
  375.      xor  ah,ah
  376.  
  377.      mov  cx,P_LEN       ; fill SCR_MAP with appropriate
  378.      mov  bx,SCR_OFF     ; characters
  379. NEXT:mov  SCR_MAP[bx],al ;
  380.      inc  bx             ;
  381.      loop next           ;
  382.  
  383.      pop  es             ; restore stack or DIE !!
  384.      pop  ds             ;
  385.      pop  bp             ;
  386.      ret
  387.  
  388. LD_SCR endp
  389. ;
  390. ;
  391. ;=========================================================
  392. ;= Utility routines.......                               =
  393. ;=========================================================
  394. ;
  395. ;*********************************************************
  396. ;* INSERT - procedure to insert keys into keyboard buffer
  397. ;*********************************************************
  398. INSERT proc    near
  399.      mov       bx,BIOS_DATA     ; point DS to the BIOS data area
  400.      mov       ds,bx            ;
  401.      assume    ds:BIOS_DATA     ;
  402.      cli                        ; disable interrupts
  403.      mov       bx,BUFFER_TAIL   ; get buffer tail address
  404.      mov       dx,bx            ; transfer it to DX
  405.      add       dx,2             ; calculate next buffer position
  406.      cmp       dx,BUFFER_END    ; did we overshoot the end?
  407.      jne       INSERT1          ; no, then continue
  408.      mov       dx,BUFFER_START  ; yes, then wrap to start 
  409.                                 ; of buffer
  410. INSERT1:
  411.      cmp       cx,BUFFER_HEAD   ; is the buffer full?
  412.      je        INSERT2          ; yes, then end now
  413.      mov       [bx],ax          ; insert the keycode
  414.      mov       bx,dx            ; advance the tail
  415.      mov       BUFFER_TAIL,bx   ; record its new position
  416.  
  417. INSERT2:
  418.      sti                        ; enable interrupts
  419.      assume    ds:nothing       ;
  420.      ret                        ; exit user sub-routine
  421. INSERT     endp
  422. ;
  423. ;
  424. ;
  425. ;****************************************************************
  426. ;* MULT10 - multiply by ten
  427. ;****************************************************************
  428. MULT10  proc  near
  429.      shl  ax,1
  430.      mov  cx,ax
  431.      shl  ax,1
  432.      shl  ax,1
  433.      add  ax,cx
  434.      ret
  435. MULT10    endp
  436.  
  437.  
  438. CODE ends
  439.      end
  440.